package com.lysh.aliHttp.model;

import com.lysh.aliHttp.event.ProgressListener;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/5/5 09:27
 * @apiNote
 */

public abstract class WebServiceRequest {
    public static final WebServiceRequest NOOP = new WebServiceRequest() {
    };
    private ProgressListener progressListener;
    private boolean logEnabled;
    private Map<String, String> parameters;
    private Map<String, String> headers;

    public WebServiceRequest() {
        this.progressListener = ProgressListener.NOOP;
        this.logEnabled = true;
        this.parameters = new LinkedHashMap();
        this.headers = new LinkedHashMap();
    }

    public void setProgressListener(ProgressListener progressListener) {
        this.progressListener = progressListener == null ? ProgressListener.NOOP : progressListener;
    }

    public ProgressListener getProgressListener() {
        return this.progressListener;
    }
/*
    public <T extends WebServiceRequest> T withProgressListener(ProgressListener progressListener) {
        this.setProgressListener(progressListener);
        return this;
    }*/

    public Map<String, String> getParameters() {
        return this.parameters;
    }

    public void setParameters(Map<String, String> parameters) {
        this.parameters = parameters;
    }

    public void addParameter(String key, String value) {
        this.parameters.put(key, value);
    }

    public Map<String, String> getHeaders() {
        return this.headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public void addHeader(String key, String value) {
        this.headers.put(key, value);
    }

    public boolean isLogEnabled() {
        return this.logEnabled;
    }

    public void setLogEnabled(boolean logEnabled) {
        this.logEnabled = logEnabled;
    }
}
